"""
施工组织
"""
import logging

import pytest
from Config.Base import Base
from playwright.sync_api import Page, expect, Playwright
from Config.config import *
from Config.URL import *
import allure, os
from Config.Base import Base
from Config.Tool import tool
from Config.Base import Base
from Config.Tool import tool

@pytest.mark.业务系统
@pytest.mark.施工管理
#@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    allure.step("登录")
    page.goto(url)
    page.get_by_placeholder("请输入用户名").fill(username_admin)
    page.get_by_placeholder("请输入密码").fill(password_admin)
    page.get_by_role("button", name="登 录").click()
    
    allure.step("跳转施工组织URL")
    page.goto(url+url_shigongzuzhi)
    page.get_by_role("button", name=" 新建").click()
    page.get_by_label("新建").get_by_placeholder("请输入组织名称").fill("AutoTest施工组织1")
    page.locator(".vue-treeselect__multi-value").click()
    page.locator(
        "div:nth-child(2) > .vue-treeselect__option > .vue-treeselect__label-container > .vue-treeselect__checkbox-container > .vue-treeselect__checkbox").click()
    page.get_by_label("新建").get_by_text("新建").click()
    page.get_by_placeholder("请输入备注").fill("备注1")
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("新建成功！")
    page.get_by_role("row", name="1 AutoTest施工组织1").get_by_role("button").nth(2).click()
    page.get_by_role("button", name=" 新建").nth(1).click()
    page.get_by_placeholder("请选择选择人员").click()
    page.get_by_placeholder("请输入用户账号").click()
    page.get_by_placeholder("请输入用户账号").fill("陈凯")
    page.get_by_placeholder("请输入用户账号").press("Enter")
    page.get_by_title("陈凯").click()
    page.get_by_label("请选择用户").get_by_role("button", name="确 定").click()
    page.get_by_role("dialog", name="新建").get_by_placeholder("请输入岗位").fill("岗位1")
    page.get_by_role("dialog", name="新建").get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("新建成功！")
    page.wait_for_timeout(3000)
    page.get_by_role("row", name="岗位1").get_by_role("button").nth(1).click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")
    page.wait_for_timeout(2000)
    page.get_by_text("返回").click()
    page.get_by_role("textbox", name="请输入组织名称").fill("AutoTest施工组织1")
    page.locator("#app").get_by_role("button", name=" 查询").click()
    page.wait_for_timeout(500)
    page.get_by_role("button", name="删除").click()
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("alert")).to_contain_text("删除成功！")

    context.close()
    SetupTeardown.close()


